const mysql = require("mysql");

const pool = mysql.createPool({
    host: "127.0.0.1",
    user: 'root',
    password: 'root',
    database: 'jddata',
    port: 3306
})

const exec = (sql, params) => {
    return new Promise(function (resolve, reject) {
        pool.getConnection(function (err, conn) {
            if (err) {
                console.log("链接数据库失败!" + err);
                reject(err)
            }
            conn.query(sql, params, function (err, result) {
                if (err) {
                    console.log("执行SQL语句失败!" + err);
                    reject(err)
                }
                resolve(result);
                conn.release();//释放链接
            })
        })
    })
}


module.exports = { exec };